import type { HttpResponse } from "@/utils/request";

// 通用ID类型定义，所有实体ID使用string类型
export type EntityId = string;

// 基础类型定义
export interface PageParams {
  current: number;
  pageSize: number;
  [key: string]: any;
}

export interface PageResult<T> {
  records: T[];
  total: number;
  current: number;
  pageSize: number;
}

// 用户相关类型定义
// 用户基本信息
export interface UserInfo {
  id: string;
  username: string;
  nickname: string;
  avatar?: string;
  email?: string;
  phone?: string;
  status: number; // 0-禁用, 1-启用
  createdTime: string;
  lastLoginTime?: string;
}

// 用户详细信息
export interface UserInfoDetailVO extends UserInfo {
  roles?: RoleVO[];
}

// 用户列表查询参数
export interface UserListParams extends PageParams {
  username?: string;
  nickname?: string;
  email?: string;
  phone?: string;
  status?: number;
  startTime?: string;
  endTime?: string;
}

// 用户列表查询结果
export type UserListResult = PageResult<UserInfoDetailVO>;

// 创建用户参数
export interface CreateUserParams {
  username: string;
  password: string;
  nickname?: string;
  email?: string;
  phone?: string;
  status?: number;
  avatar?: string;
}

// 更新用户参数
export interface UpdateUserParams {
  id: string;
  nickname?: string;
  email?: string;
  phone?: string;
  status?: number;
  avatar?: string;
}

// 更新用户状态参数
export interface UpdateUserStatusParams {
  userId: string;
  status: number;
}

// 修改密码参数
export interface ChangePasswordParams {
  oldPassword: string;
  newPassword: string;
  confirmPassword: string;
}

// 管理员修改用户密码参数
export interface AdminChangePasswordParams {
  userId: string;
  newPassword: string;
  confirmPassword: string;
}

// 用户角色分配参数
export interface UserRoleAssignParams {
  userId: string;
  roleIds: string[];
}

// 批量用户角色分配参数
export interface BatchUserRoleAssignParams {
  userIds: string[];
  roleIds: string[];
}

// 角色相关类型定义
// 角色信息
export interface RoleVO {
  id: string;
  name: string;
  code: string;
  description?: string;
  status: number; // 0-禁用, 1-启用
  createdTime: string;
}

// 角色列表查询参数
export interface RoleListParams extends PageParams {
  name?: string;
  code?: string;
  status?: number;
}

// 角色列表查询结果
export type RoleListResult = HttpResponse<PageResult<RoleVO>>;

// 创建角色参数
export interface CreateRoleParams {
  name: string;
  code: string;
  description?: string;
  status?: number;
}

// 更新角色参数
export interface UpdateRoleParams {
  id: string;
  name?: string;
  code?: string;
  description?: string;
  status?: number;
}

// 更新角色状态参数
export interface UpdateRoleStatusParams {
  roleId: string;
  status: number;
}

// 角色权限分配参数
export interface RolePermissionAssignParams {
  roleId: string;
  permissionIds: string[];
}

// 角色菜单分配参数
export interface RoleMenuAssignParams {
  roleId: string;
  menuIds: string[];
}

// 权限相关类型定义
// 权限信息
export interface PermissionVO {
  id: string;
  name: string;
  code: string;
  parentId: string;
  status: number;
  createdTime: string;
  type: number; // 1-目录，2-接口
  description?: string;
}

// 权限树结构
export interface PermissionTree {
  id: string;
  name: string;
  children?: PermissionTree[];
}

// 权限列表查询参数
export interface PermissionListParams extends PageParams {
  name?: string;
  code?: string;
  parentId?: string;
  status?: number;
}

// 创建权限参数
export interface CreatePermissionParams {
  name: string;
  code: string;
  moduleId: string;
  status?: number;
}

// 更新权限参数
export interface UpdatePermissionParams {
  id: string;
  name?: string;
  code?: string;
  type?: number;
  parentId?: string;
  status?: number;
  description?: string;
}

// 更新权限状态参数
export interface UpdatePermissionStatusParams {
  permissionId: string;
  status: number;
}

// 菜单相关类型定义
// 菜单类型
export enum MenuType {
  DIRECTORY = 1, // 目录
  MENU = 2, // 菜单
  BUTTON = 3 // 按钮
}

// 菜单信息
export interface MenuVO {
  id: string;
  parentId: string;
  name: string;
  path: string;
  component?: string;
  redirect?: string;
  icon?: string;
  type: MenuType;
  permission?: string;
  sort: number;
  hidden: boolean;
  status: number; // 0-禁用, 1-启用
  createdTime: string;
}

// 菜单树结构
export interface MenuTree extends MenuVO {
  children?: MenuTree[];
}

// 创建菜单参数
export interface CreateMenuParams {
  parentId: string;
  name: string;
  path: string;
  component?: string;
  redirect?: string;
  icon?: string;
  type: MenuType;
  permission?: string;
  sort?: number;
  hidden?: boolean;
  status?: number;
}

// 更新菜单参数
export interface UpdateMenuParams {
  id: string;
  parentId?: string;
  name?: string;
  path?: string;
  component?: string;
  redirect?: string;
  icon?: string;
  type?: MenuType;
  permission?: string;
  sort?: number;
  hidden?: boolean;
  status?: number;
}

// 操作日志相关类型定义
// 操作类型
export enum OperationType {
  CREATE = 1, // 创建
  UPDATE = 2, // 更新
  DELETE = 3, // 删除
  QUERY = 4, // 查询
  IMPORT = 5, // 导入
  EXPORT = 6, // 导出
  OTHER = 99 // 其他
}

// 操作日志信息
export interface OperationLogVO {
  id: string;
  userId: string;
  username: string;
  operation: string;
  method: string;
  params: string;
  time: number;
  ip: string;
  systemModule: string;
  operationType: OperationType;
  createdTime: string;
}

// 操作日志列表查询参数
export interface OperationLogListParams extends PageParams {
  username?: string;
  operation?: string;
  systemModule?: string;
  operationType?: OperationType;
  startTime?: string;
  endTime?: string;
}

// 操作日志列表查询结果
export type OperationLogListResult = HttpResponse<PageResult<OperationLogVO>>;
